package com.user.servlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.user.entity.user;
import com.user.service.userservice;

@WebServlet("/Doadduser")
public class Doadduser extends HttpServlet{
	private static final long serialVersionUID = 1L;
    
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Doadduser() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		response.setContentType("textml;charset=utf-8");
		String username = request.getParameter("username");
		String password =request.getParameter("password");
		String phone =request.getParameter("phone");
			user pu=new user();
			pu.setUsername(username);
			pu.setPassword(password);
			pu.setPhone(Integer.parseInt(phone));
			userservice p=new userservice();
			int i=p.adduser(pu);
			if(i>0){
				request.setAttribute("msg", "注册成功！");
				System.out.println("注册成功！");
				request.getRequestDispatcher("login.jsp").forward(request, response);
			}else{
				request.setAttribute("msg", "注册失败！!!");
				System.out.println("注册失败！");
				request.getRequestDispatcher("login.jsp").forward(request, response);
			}	
		}
		

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request,response);

	}

}
